import { useEffect } from "react"
import { useHttp } from "./http"
import { cleanObject } from "utils"
import { useAsync } from "./use-async"
import { User } from "screens/project-list/search-panel"

export function useUsers(param?: Partial<User>) {
  const client = useHttp()
  const {run, ...result} = useAsync<User[]>()

  useEffect(() => {
    run(client('users', {data: cleanObject(param || {})}))
  }, [param])

  return result
}